package cn.kgc.countservice.service;


import cn.kgc.countservice.dao.RedisDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class AddressServiceImpl implements AddressService{

    @Autowired
    private RedisDao redisDao;

    @Override
    public Integer addOneAddress(Integer newsId, String address) {
        redisDao.hyperLogAdd("ip:"+newsId, address);
        return redisDao.hyperLogCount("ip:"+newsId);
    }

    @Override
    public Map<Integer, Integer> getAllCounts(List<Integer> list) {
        Map<Integer, Integer> result = new HashMap<>();
        for (Integer i : list) {
            String key = "ip:" + i;
            Integer count = redisDao.hyperLogCount(key);
            result.put(i, count);
        }
        return result;
    }

    @Override
    public List<Integer> getHotNews(List<Integer> newsIdList) {
        return redisDao.getHotNews(newsIdList);
    }

    @Override
    public long zSetRemove(String key, Integer min, Integer max) {
        return redisDao.zSetRemove(key, min, max);
    }

    @Override
    public void setHot(String key, String value) {
        redisDao.setHot(key, value);
    }

    @Override
    public String getHot(String key) {
        return redisDao.getHot(key);
    }
}
